package Simple3;

import java.util.ArrayList;

public class byteToString {

	public String hex_to_decimal(byte[] input){
		ArrayList<String> list = new ArrayList<>();
		boolean allzero = false;
		while(true){
			int m = 0;
			for(int i=0;i<input.length;++i){
				int temp = m*256 + (int) (input[i] & 0xFF);
				if(temp==0 && i==input.length-1){
					allzero = true;
					break;
				}
				m = (int)temp%10;
				input[i] =  (byte) (temp/10);
			}
			if(allzero) break;
			list.add(0,m+"");
		}
		String ret = "";
		for(int i=0;i<list.size();++i){
			ret+=list.get(i);
		}
		return ret;
		
	}
	
	public void nextPermutation(int[] num) {
        if(num.length<=1) return;
        int flag = num.length-2;
        //assume num is 5524763, we must find 552[4]763
        while(flag>=0 && num[flag]>=num[flag+1])
            --flag;
            
        //321 next permutation is 123, reverse back
        if(flag<0){
            reverse(num,0,num.length-1);
        }
        else{
            int flag2 = num.length-1;
            
            //find 552[4]7(6)3----> 552(6)7[4]3
            //the right answer is   552(6)3[4]7
            while(num[flag]>=num[flag2]){
                --flag2;
            }
            int temp = num[flag];
            num[flag] = num[flag2];
            num[flag2] = temp;
            reverse(num,flag+1,num.length-1);
        }
    }
    
    public void reverse(int[] num, int i, int j){
        while(i<=j){
            int temp = num[i];
            num[i++] = num[j];
            num[j--] = temp;
        }
    }
	
	
	
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		byteToString test = new byteToString();
		int[] t_array = {255,255};
//		test.nextPermutation(t_array);
//		for(int i=0;i<t_array.length;i++){
//			System.out.print(t_array[i]+" ");
//		}
		
		byte[] bytearray = new byte[t_array.length];
		for(int i=0;i<t_array.length;++i){
			bytearray[i] = (byte)t_array[i];
		}
		
		System.out.println(test.hex_to_decimal(bytearray));
	}

}
